const user = {
    state: {
        HOST: 'http://localhost:8888',
        token: '',
        userInfo: '',
        //JSON.parse(sessionStorage.getItem("userInfo"))
        //sessionStorage中得userInfo是序列化得字符串，这里要将他反序列化成对象。
    },
    mutations: {
        SET_TOKEN: (state, token) => {
            state.token = token
            localStorage.setItem("token", token)
        },
        SET_USERINFO: (state, userInfo) => {
            state.userInfo = userInfo
            localStorage.setItem("userInfo",JSON.stringify(userInfo))
            //sessionStorage中不可以存入对象，所以要将他序列化
            sessionStorage.setItem("userInfo", JSON.stringify(userInfo))
        },

        REMOVE_INFO: (state) => {
            localStorage.setItem("userInfo",'');
            localStorage.setItem("loginAuto",'')
            sessionStorage.setItem("userInfo", JSON.stringify(''))
            localStorage.setItem("token","")
            state.userInfo = {}
        },
    },
    getters: {
        getUser: state => {
            const ones = JSON.parse(localStorage.getItem("userInfo"));
            return ones;
        },
        getHost: state =>{
            return state.HOST;
        },

    },
    actions: {},
    modules: {}
}

export default user
